package cn.unknowpupil.sms.controller;

import cn.unknowpupil.common.core.resopnse.ResultResponse;
import cn.unknowpupil.common.core.utils.StringUtils;
import cn.unknowpupil.common.core.utils.ValidateMobileUtil;
import cn.unknowpupil.sms.service.IAliyunSmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



/**
 * Created at 2020/10/21 by w10g <br>
 * Initialize SmsController ... <br>
 *
 * @author unknowpupil
 * @since 0.0.1
 */
@RestController
@RequestMapping(value = "sms")
public class SmsController {

    @Autowired
    IAliyunSmsService aliyunSmsService;


    @PostMapping(value = "send/{mobile}")
    public ResultResponse sendSms(@PathVariable("mobile") String mobile) {
        if (StringUtils.isEmpty(mobile)) {
            return ResultResponse.buildFailure("手机号不能为空");
        }
        mobile = mobile.trim();
        boolean result = ValidateMobileUtil.isPhoneLegal(mobile);
        if (!result) {
            return ResultResponse.buildFailure("手机号格式不正确，请重新输入！！！");
        }
        return ResultResponse.buildSuccess();
    }

    @PostMapping(value = "echo")
    public ResultResponse echo() {
        return ResultResponse.buildSuccess("可以访问");
    }


}
